package com.zb.zeus.system.api.factory;

import org.springframework.stereotype.Component;

import com.zb.zeus.common.core.domain.R;
import com.zb.zeus.system.api.RemoteSysWxMsgService;
import com.zb.zeus.system.api.domain.dto.WxAppNewsMsgDTO;
import com.zb.zeus.system.api.domain.dto.WxAppTextCardDTO;
import com.zb.zeus.system.api.domain.dto.WxAppTextMsgDTO;
import com.zb.zeus.system.api.domain.dto.WxGroupNewsMsgDTO;
import com.zb.zeus.system.api.domain.dto.WxGroupTextCardMsgDTO;
import com.zb.zeus.system.api.domain.dto.WxGroupTextMsgDTO;
import com.zb.zeus.system.api.domain.dto.WxMsgRspDTO;

import javax.validation.Valid;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * 发企业微信系统降级
 * 
 * @author liangfan
 * @date 2021/07/12 15:27
 **/
@Component
@Slf4j
public class RemoteSysWxMsgFallbackFactory implements FallbackFactory<RemoteSysWxMsgService> {

    @Override
    public RemoteSysWxMsgService create(Throwable throwable) {
        log.error("发企业微信调用失败:", throwable);
        return new RemoteSysWxMsgService(){

            @Override
            public R<WxMsgRspDTO> sendAppTextMsg2Wx(@Valid WxAppTextMsgDTO wxAppTextMsgDTO) {
                return R.fail("发应用文本企业微信消息失败:" + throwable.getMessage());
            }

            @Override
            public R<WxMsgRspDTO> sendAppNewsMsg2Wx(@Valid WxAppNewsMsgDTO wxAppNewsMsgDTO) {
                return R.fail("发应用图文企业微信消息失败:" + throwable.getMessage());
            }

            @Override
            public R<WxMsgRspDTO> sendAppTextCardMsg2Wx(@Valid WxAppTextCardDTO wxAppTextCardDTO) {
                return R.fail("发应用卡片企业微信消息失败:" + throwable.getMessage());
            }

            @Override
            public R<WxMsgRspDTO> sendGroupTextMsg2Wx(@Valid WxGroupTextMsgDTO wxGroupTextMsgDTO) {
                return R.fail("发文本群微信消息失败:" + throwable.getMessage());
            }

            @Override
            public R<WxMsgRspDTO> sendGroupNewsMsg2Wx(@Valid WxGroupNewsMsgDTO wxGroupNewsMsgDTO) {
                return R.fail("发图文群微信消息失败:" + throwable.getMessage());
            }

            @Override
            public R<WxMsgRspDTO> sendGroupTextCardMsg2Wx(@Valid WxGroupTextCardMsgDTO wxGroupTextCardMsgDTO) {
                return R.fail("发卡片群微信消息失败:" + throwable.getMessage());
            }
        };
    }
}
